import os
import urllib.request
import stock_list

filename = './analyse_data/沪深Ａ股20210529.txt'

saveDir = './analyse_data/a'

if __name__ == "__main__" :
    
    # print(stock_list.getStockInfoList(filename))

    codeList = stock_list.getStockCodeList(filename)

    os.makedirs(saveDir, exist_ok=True)
    saveFilePattern = saveDir + '/%s.txt'
    
    for code in codeList :
        saveFilename = saveFilePattern % code
        if os.path.exists(saveFilename) :
            continue

        with open(saveFilename, 'wb') as f2 :
            url = urllib.request.urlopen("http://quotes.money.163.com/service/zycwzb_%s.html?type=report" % code)
            content = url.read()
            f2.write(content)
        
        if os.path.getsize(saveFilename) <= 415:
            os.remove(saveFilename)